from selenium import webdriver
from scrapy.selector import Selector
import time

browser = webdriver.Chrome(executable_path="D:/scrapy/webdriver/chromedriver_win32/chromedriver.exe")
# browser.get("https://my.oschina.net/xxiaobian")
# browser.get("https://www.shixiseng.com/")
# time.sleep(15)  #设置睡眠时间
# 模拟登录
# browser.find_element_by_css_selector("#log_name").send_keys("13395993129")
# browser.find_element_by_css_selector(".password").send_keys("123456")
# browser.find_element_by_css_selector("#index_login_btn").click()

#模拟鼠标下滑
for i in range(100):
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight); var lenOfPage=document.body.scrollHeight; return lenOfPage;")
    # time.sleep(2)
# t_selector = Selector(text=browser.page_source)
# print(t_selector.css(".box-title ::text").extract())

#设置不加载图片
# chrome_opt = webdriver.ChromeOptions()
# prefs = {"profile.managed_default_content_settings.images":2}
# chrome_opt.add_experimental_option("prefs", prefs)
# browser = webdriver.Chrome(executable_path="D:/scrapy/webdriver/chromedriver_win32/chromedriver.exe", chrome_options=chrome_opt)
# browser.get("https://my.oschina.net/xxiaobian")

#phantomjs, 无界面的浏览器， 多进程情况下phantomjs性能会下降很严重

browser = webdriver.PhantomJS(executable_path="D:/scrapy/webdriver/phantomjs-2.1.1-windows/bin/phantomjs.exe")
browser.get("https://detail.tmall.com/item.htm?spm=a230r.1.14.3.yYBVG6&id=538286972599&cm_id=140105335569ed55e27b&abbucket=15&sku_properties=10004:709990523;5919063:6536025")

print (browser.page_source)
browser.quit()